(function($, window) {
	var v3Restshop = window.v3Restshop = {};
	var baseRequest = window.baseRequest;
	var appConfig = window.appConfig;
	var commonTool = window.commonTool;
	var dataManager = window.dataManager;
	var baseUrl = appConfig.v3ServiceUrl + '/ace/oasis/oasis-rest-shop/restshop';
	
	//Add by dongyi
	var shop = baseUrl + '/appshopdevices?';
	v3Restshop.gerShop = function(size, region_id, status, callback){
		baseRequest.commonGet(shop +$.param({
			start: 1,
			size: size,
			orderby: 'shopName',
			ascending: true,
			region_id: region_id,
			status: status
		}), 10000, function(code, data){
			 if (code === 2 || code === 1) {
                return callback(2);
            }
            if (data.code === 0) {
                callback(0, data);
            } else {
                callback(1, data.message);
            }
		})
	}
	
	var getShopList = baseUrl + '/shopModel/getPlaceInfoListPage?';
    //获取场所信息
    v3Restshop.getShopListOfUser = function (userName, queryCondition, start, size, callback) {
        baseRequest.commonGet(getShopList + mui.param({
                queryCondition: queryCondition,
                start: start,
                size: size,
                user_name: userName
            }), 15000, function (code, data) {
            if (code === 2 || code === 1) {
                return callback(2);
            }
            if (data.code === 0) {
                callback(0, data.data);
            } else {
                callback(1, data.message);
            }
        });
    }
    //获取场所下所有设备
    v3Restshop.getDevicesOfShop = function(userName, shopId,callback){
    	var getDevicesOfShopUrl = baseUrl + "/shopModel/shopdevices2/"+shopId+"?user_name="+userName;
		baseRequest.commonGet(getDevicesOfShopUrl, function (code, data) {
            if (code === 2 || code === 1) {
                return callback(2);
            }
            if (code === 0) {
                if (data.code === 0) {
                    callback(0,data.data);
                } else {
                    callback(1, data.message);
                }
            }
        });
	}
    
    //添加设备
    var addDeviceUrl = baseUrl + "/shopModel/shopdevices2App";
    v3Restshop.addDevice = function (deviceInfo,callback) {
        baseRequest.commonPost(addDeviceUrl, deviceInfo, function (code, data) {
            if (code === 2 || code === 1) {
                return callback(2);
            }
            if (data.code === 0) {
                callback(0, data.data);
            } else {
                callback(1, data.message);
            }
        });
    }
    
    //获取场所设备所有分组
    var getGroupInfoUrl = baseUrl + "/shopModel/getdevicegroupbyshopid?";
    v3Restshop.getGroupInfo = function (userName, nasId, callback) {
   	 	baseRequest.commonGet(getGroupInfoUrl + mui.param({
   	 		 user_name: userName,
   	 		 shop_id: nasId
   	 	}), function (code, data) {
            if (code === 2 || code === 1) {
                return callback(2);
            }
            if (code === 0) {
                if (data.code === 0) {
                    callback(0,data.data);
                } else {
                    callback(1, data.message);
                }
            }
        });
    }
    
    //删除设备
    v3Restshop.deleteDevice = function(userName,deviceId,callback){
    	var deleteDeviceUrl = baseUrl + "/shopModel/shopdevices/" + deviceId + "?user_name=" + userName;
	    baseRequest.commonDelete(deleteDeviceUrl, function(code, data) {
		    	if(code === 2 || code === 1) {
		    		return callback(2);
		    	}
		    	if(code === 0) {
		    		if(data.code === 0) {
		    			callback(0);
		    		} else {
		    			callback(1);
		    		}
		    	}
	    });
    }
    
    //删除场所
    v3Restshop.deleteShopByShopId = function (userName,shopId,callback){
    		var deleteShopUrl = baseUrl + "/shopModel/shops/" + shopId + "?user_name=" + userName;
    		baseRequest.commonDelete(deleteShopUrl, function(code, data) {
		    	if(code === 2 || code === 1) {
		    		return callback(2);
		    	}
		    	if(code === 0) {
		    		if(data.code === 0) {
		    			callback(0);
		    		} else {
		    			callback(1,data.message);
		    		}
		    	}
	    });
    }
  	
  	//获取场景所属区域
    var getRegionUrl = baseUrl + '/regioninfo/regions?';
    v3Restshop.getRegion = function (userName, callback) {
        baseRequest.commonGet(getRegionUrl + mui.param({
                user_name: userName
            }), 5000, function (code, data) {
            if (code === 2 || code === 1) {
                return callback(2);
            }
            if (code === 0) {
                if (data.code === 0) {
                	callback(0, data.data);
                } else {
                    callback(1);
                }
            }
        });
    }
    
    //获取场景所属行业
    var getIndustryUrl = baseUrl + '/shopModel/getAllIndustryName?';
    v3Restshop.getIndustry = function (userName, callback) {
        baseRequest.commonGet(getIndustryUrl + mui.param({
                user_name: userName
            }), 5000, function (code, data) {
            if (code === 2 || code === 1) {
                return callback(2);
            }
            if (code === 0) {
                if (data.code === 0) {
                	callback(0, data.data);
                } else {
                    callback(1);
                }
            }
        });
    }
    
     //添加场所
    var addPlaceUrl = baseUrl + '/shopModel/addShopApp';
    v3Restshop.addPlace = function (placeInfo, callback) {
        baseRequest.commonPost(addPlaceUrl, placeInfo, 5000, function (code, data) {
            if (code === 2 || code === 1) {
                return callback(2);
            }
            if (data.code === 0) {
                callback(0, data.data);
            } else {
                callback(1, data.message);
            }
        });
    }
    
    /**
     * 获取所有的设备信息
     * @type {string}
     */
    var deviceInfoUrl = baseUrl + '/o2oportal/getDeviceInfo';
    v3Restshop.getDeviceInfo = function (userName,callback) {
        baseRequest.commonPost(deviceInfoUrl, {
            tenant_name: userName
        }, function (code, data) {
            if (code === 1 || code === 2) {
                return callback(2);
            }
            if (!data.dev_list) {
                return callback(1,locale.base.err.request); // TODO 获取设备信息失败
            }
            callback(0, data.dev_list);
        });
    };
	// end
	
	
	/* lkf6877 start */
	v3Restshop.getallshopsofuser = function(callback){
		baseRequest.commonGet(baseUrl + '/shopModel/getallshopsofuser', 10000, function(code, data){
			if (code === 2 || code === 1) {
                return callback(2);
            }
            if (data.code === 0) {
                callback(0, data.data);
            } else {
                callback(1, data.message);
            }
		})
	}
	/* lkf6877 end */
})(mui, window);